package com.kzd.gtboon.main.access

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.widget.addTextChangedListener
import com.kzd.gtboon.custom.setOnClickAntiShakeListener
import com.kzd.gtboon.databinding.FragmentAccessVerifyBinding
import com.kzd.gtboon.jetpack.vm.AccessViewModel
import com.module.lemlin.owner.OwnerViewBindingFragment
import com.module.lemlin.owner.ownerViewModel

class AccessVerifyFragment : OwnerViewBindingFragment<FragmentAccessVerifyBinding>() {

    companion object {
        fun newInstance(): AccessVerifyFragment {
            return AccessVerifyFragment()
        }
    }

    private val mViewModel: AccessViewModel by lazy {
        ownerViewModel(requireActivity())
    }

    override val inflate: (LayoutInflater, ViewGroup?, Boolean) -> FragmentAccessVerifyBinding
        get() = FragmentAccessVerifyBinding::inflate

    override fun initView() {
        mViewBinding.etAccessVerifyName.addTextChangedListener {
            mViewBinding.tvAccessVerifySubmit.isEnabled = !it.isNullOrEmpty() &&
                    !mViewBinding.etAccessVerifyCode.text.isNullOrEmpty()
        }
        mViewBinding.etAccessVerifyCode.addTextChangedListener {
            mViewBinding.tvAccessVerifySubmit.isEnabled = !it.isNullOrEmpty() &&
                    !mViewBinding.etAccessVerifyName.text.isNullOrEmpty()
        }

        mViewBinding.tvAccessVerifySubmit.setOnClickAntiShakeListener {
            mViewModel.userChange(
                name = mViewBinding.etAccessVerifyName.text.toString(),
                idcard = mViewBinding.etAccessVerifyCode.text.toString()
            )
        }
    }


}